home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / kiconloader.h.z / kiconloader.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  5.5 KB  |  178 lines

  1. /* 
  2.    $Id: kiconloader.h,v 1.10 1998/06/16 06:03:22 kalle Exp $
  3.    
  4.    This file is part of the KDE libraries
  5.    Copyright (C) 1997 Christoph Neerfeld (Christoph.Neerfeld@boon.netsurf.de)
  6.    
  7.    This library is free software; you can redistribute it and/or
  8.    modify it under the terms of the GNU Library General Public
  9.    License as published by the Free Software Foundation; either
  10.    version 2 of the License, or (at your option) any later version.
  11.    
  12.    This library is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.    Library General Public License for more details.
  16.    
  17.    You should have received a copy of the GNU Library General Public License
  18.    along with this library; see the file COPYING.LIB.  If not, write to
  19.    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20.    Boston, MA 02111-1307, USA.
  21.    
  22.    $Log: kiconloader.h,v $
  23.    Revision 1.10  1998/06/16 06:03:22  kalle
  24.    Implemented copy constructors and assignment operators or disabled them
  25.  
  26.    Revision 1.9  1998/03/08 18:50:23  wuebben
  27.    Bernd: fixed up the kiconloader class -- it was completely busted
  28.  
  29.  
  30. */
  31.  
  32.  
  33. #ifndef KICONLOADER_H
  34. #define KICONLOADER_H
  35.  
  36. #ifndef _KCONFIG_H
  37. #include <kconfig.h>
  38. #endif
  39.  
  40. #include <qapp.h>
  41. #include <qlist.h>
  42. #include <qpixmap.h>
  43. #include <qstrlist.h>
  44. #include <qstring.h>
  45.  
  46. /// Load icons from disk
  47. /**
  48.    KIconLoader is a derived class from QObject.
  49.    It supports loading of icons from disk. It puts the icon and its name
  50.    into a QList and if you call loadIcon() for a second time, the icon is taken
  51.    out of the list and not reread from disk.
  52.    So you can call loadIcon() as many times as you wish and you don't have
  53.    to take care about multiple copies of the icon in memory.
  54. */
  55. class KIconLoader : public QObject
  56. {
  57.   Q_OBJECT
  58. public:
  59.   /// Constructor
  60.   /**
  61.      config is the pointer to a KConfig object; 
  62.      normally the global KConfig object.
  63.      group is the name of a group in a config file.
  64.      key is the name of an entry within this group.
  65.      
  66.      Normaly group == "KDE Setup" and key == "IconPath"
  67.      Example for an entry in .kderc:
  68.      [KDE Setup]
  69.      IconPath=/usr/local/lib/kde/lib/pics:/usr/local/lib/kde/lib/pics/toolbar
  70.      
  71.      This gives KIconLoader the path to search the icons in.
  72.      
  73.      If you want to use another path in your application then write into
  74.      your .my_application_rc:
  75.      [MyApplication]
  76.      PixmapPath=/..../my_pixmap_path
  77.      and call KIconLoader( config, "MyApplication", "PixmapPath" ).
  78.   */
  79.   KIconLoader ( KConfig *conf, const QString &app_name, const QString &var_name );
  80.  
  81.   /**
  82.      There now exists a simple-to-use version of KIconLoader. If you
  83.       create a KIconLoader without giving arguments, KIconLoader searches for 
  84.      the path in [KDE Setup]:IconPath=... as a default.
  85.   */
  86.   KIconLoader();
  87.  
  88.   /// Destructor
  89.   ~KIconLoader ();
  90.  
  91.   /// Load an icon from disk
  92.   /**
  93.      This function searches for the icon called name 
  94.      and returns a QPixmap object
  95.      of this icon if it was found and 0 otherwise.
  96.      If name starts with "/..." loadIcon treats it as an absolut pathname.
  97.      LoadIcon() creates a list of all loaded icons, 
  98.      so calling loadIcon() a second time
  99.      with the same name argument won't load the icon again, but gets it out of
  100.      its cache. By this you don't have to worry about multiple copies
  101.      of one and the same icon in memory, and you can call loadIcon() 
  102.      as often as you like.
  103.  
  104.          If the icon is larger then the specified size, it is 
  105.          scaled down automatically. If the specified size is 
  106.          0, the icon is not scaled at all.
  107.  
  108.   */
  109.   QPixmap loadIcon( const QString &name, int w = 0, int h = 0 );
  110.  
  111.   /// Load an mini icon from disk
  112.   /**
  113.      Same like loadIcon, but looks for "mini/name" first.
  114.   */
  115.   QPixmap loadMiniIcon( const QString &name , int w = 0, int h = 0 );
  116.  
  117.   /* 
  118.    * The loadApplication-Icon functions are similar to the 
  119.    * usual loadIcon functions except that they look in
  120.    * kdedir()/share/icon first.
  121.    *
  122.    * These function should be used if you are loading the
  123.    * application icons. Normally KApplication does this for
  124.    * you, but special programs like kpanel or kmenuedit
  125.    * need to load the application icons of foreign applications.
  126.    */
  127.   QPixmap loadApplicationIcon( const QString &name, int w = 0, int h = 0 );
  128.   QPixmap loadApplicationMiniIcon( const QString &name, int w = 0, int h = 0 );
  129.  
  130.  
  131.   /// Insert directory into searchpath
  132.   /**
  133.          This functions inserts a new directory into the searchpath at 
  134.      position index.
  135.      It returns TRUE if successful, or FALSE if index is out of range.
  136.      Note that the default searchpath looks like this:
  137.  
  138.            0: kdedir()/share/apps/<appName>/toolbar
  139.            1: kdedir()/share/toolbar
  140.            2: kdedir()/share/apps/<appName>/pics
  141.  
  142.            3: $HOME/.kde/share/apps/<appName>/toolbar
  143.            4: $HOME/.kde/share/toolbar
  144.            5: $HOME/.kde/share/apps/<appName>/pics
  145.  
  146.          6-x: list of directories in [KDE Setup]:IconPath=...
  147.  
  148.   */
  149.  
  150.   bool insertDirectory( int index, const QString &dir_name ) {
  151.     return pixmap_dirs.insert( index, dir_name ); }
  152.   QStrList* getDirList() { return &pixmap_dirs; }
  153.  
  154.  
  155.  
  156. protected:
  157.   KConfig           *config;
  158.   QStrList           name_list;
  159.   QStrList           pixmap_dirs;
  160.   QList<QPixmap>     pixmap_list;
  161.   QPixmap loadInternal(const QString &name, int w = 0, int h = 0 );
  162.  
  163. private:
  164.  
  165.   void addPath(QString path);
  166.  
  167.   // Disallow assignment and copy-construction
  168.   KIconLoader( const KIconLoader& ) {};
  169.   KIconLoader& operator= ( const KIconLoader& ) { return *this; }
  170.  
  171. };
  172.  
  173. #endif // KICONLOADER_H
  174.  
  175.  
  176.  
  177.  
  178.